// novan_tools.js

/**
 * Utk Float Menu
 */
function JSFX_FloatTopDiv(verticalpos, vDivName, vXpos, vYpos) {
	var startX = vXpos,
	startY = vYpos;
	var ns = (navigator.appName.indexOf("Netscape") != -1);
	var d = document;
	function ml(id) {
		var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
		if(d.layers)el.style=el;
		el.sP=function(x,y){this.style.left=x;this.style.top=y;};
		el.x = startX;
		if (verticalpos=="fromtop")
		el.y = startY;
		else{
		el.y = ns ? pageYOffset + innerHeight : document.body.scrollTop + document.body.clientHeight;
		el.y -= startY;
		}
		return el;
	}
	window.stayTopLeft=function() {
		if (verticalpos=="fromtop"){
		var pY = ns ? pageYOffset : document.body.scrollTop;
		ftlObj.y += (pY + startY - ftlObj.y)/8;
		}
		else{
		var pY = ns ? pageYOffset + innerHeight : document.body.scrollTop + document.body.clientHeight;
		ftlObj.y += (pY - startY - ftlObj.y)/8;
		}
		ftlObj.sP(ftlObj.x, ftlObj.y);
		setTimeout("stayTopLeft()", 10);
	}
	ftlObj = ml(vDivName);
	stayTopLeft();
}
 
/**
 * function change case
 * 1 : UPPERCASE, input: aAa bBb, output: AAA BBB
 * 2 : LOWERCASE, input: aAa bBb, output: aaa bbb
 * 3 : TITLE, input: aAa bBb, output: Aaa Bbb
 */
function fnChangeCase(vType, vWord) {
	if (vType == 1) {
		vWord = vWord.toUpperCase();
	} else if (vType == 2) {
		vWord = vWord.toLowerCase();
	} else if (vType == 3) {
		vWord = vWord.toLowerCase();
		var vLength = vWord.length;
		for (var a=0; a<=vLength-1; a++) {
			if (a == 0) {
				var vChar = vWord.charAt(0).toUpperCase();
				vWord = vChar + vWord.substr(1,vWord.length);
			} else {
				var vChar1 = vWord.charAt(a);
				if (vChar1 == ' ') {
					var vChar2 = vWord.charAt(a+1).toUpperCase();
					vWord = vWord.substr(0,a+1) + vChar2 + vWord.substr(a+2,vWord.length);

				}
			}
		}
	} else {
		vWord = vWord;	
	}
	return vWord;
}

/**
 * function custom dialog
 */
function fnCustomDialog(vLocation, vWinName, vType, vQuestion) {
	var vWinWidth = document.body.offsetWidth;
	var vWinHeight = document.body.offsetHeight;
	var vXPos = (vWinWidth - 300) / 2;
	var vYPos = (vWinHeight - 200) / 2;
	var vLocation = vLocation + 'common/novan_CustomDialog.jsp?tipe=' + vType + '&question=' + vQuestion;
	var vProperties = 'dialogWidth=300px;dialogHeight=200px;dialogTop='+vYPos+';dialogLeft='+vXPos+';resizable=no;status=no';
	var retValue = window.showModalDialog(vLocation, vWinName, vProperties); 
	return retValue;
}

/**
 * function open window
 */
function fnOpenWindow(vLocation, vWinName, pctWMainWindow) {
	var vAvailWidth = screen.availWidth;
	var vAvailHeight = screen.availHeight;
	
	var vMainWidth= 0;
	var vMainHeight= 0;  
	var vWinWidth = 0;
	var vWinHeight = 0;
	var vWinXPos = 0;
	var vWinYPos = 0;
		
	if ((parseInt(vAvailWidth) > 1024) && (parseInt(vAvailHeight ) > 768)) {
		vMainWidth= parseInt(screen.availWidth * parseFloat(pctWMainWindow));
		vMainHeight= parseInt(screen.availHeight) - 38;  
		vWinWidth = screen.availWidth - parseInt(vMainWidth) - 24;
		vWinHeight = vMainHeight;
		vWinXPos = parseInt(vMainWidth) + 14;
		vWinYPos = 0;
	} else {
		vMainWidth= parseInt(screen.availWidth);
		vMainHeight= parseInt(screen.availHeight);
		vWinWidth = 800;
		vWinHeight = 600;
		vWinXPos = (vMainWidth - vWinWidth) / 2;
		vWinYPos = (vMainHeight - vWinHeight) / 2;
	}
	
	var vProperties = 'width='+vWinWidth+',height='+vWinHeight+',top='+vWinYPos+',left='+vWinXPos+',menubar=no,resizable=yes,location=no,status=0,scrollbars=yes';
	var retValue = window.open(vLocation, vWinName, vProperties); 
	return retValue;
}

/**
 * function small dialog
 */
function fnSmallDialog(vLocation, vWinName) {
	var vProperties = 'dialogWidth=10px;dialogHeight=10px;dialogTop=0;dialogLeft=0;resizable=no;status=no';
	var retValue = window.showModalDialog(vLocation, vWinName, vProperties); 
	return retValue;
}

/**
 * function modal dialog
 */
function fnOpenDialog(vLocation, vWinName, pctWMainWindow) {
	var vAvailWidth = screen.availWidth;
	var vAvailHeight = screen.availHeight;
	
	var vMainWidth= 0;
	var vMainHeight= 0;  
	var vWinWidth = 0;
	var vWinHeight = 0;
	var vWinXPos = 0;
	var vWinYPos = 0;
		
	if ((parseInt(vAvailWidth) > 1024) && (parseInt(vAvailHeight ) > 768)) {
		vMainWidth= parseInt(screen.availWidth * parseFloat(pctWMainWindow));
		vMainHeight= parseInt(screen.availHeight) - 38;  
		vWinWidth = screen.availWidth - parseInt(vMainWidth) - 24;
		vWinHeight = vMainHeight;
		vWinXPos = parseInt(vMainWidth) + 14;
		vWinYPos = 0;
	} else {
		vMainWidth= parseInt(screen.availWidth);
		vMainHeight= parseInt(screen.availHeight);
		vWinWidth = 800;
		vWinHeight = 600;
		vWinXPos = (vMainWidth - vWinWidth) / 2;
		vWinYPos = (vMainHeight - vWinHeight) / 2;
	}
	
	var vProperties = 'dialogWidth='+vWinWidth+'px;dialogHeight='+vWinHeight+'px;dialogTop='+vWinYPos+';dialogLeft='+vWinXPos+';resizable=no;status=0';
	var retValue = window.showModalDialog(vLocation+"&width_scr="+screen.availWidth+"&height_scr="+screen.availHeight, vWinName, vProperties); 
	return retValue;
}

/**
 * filter untuk text box
 * tipe 0 : huruf
 * tipe 1 : angka
 * tipe 2 : huruf dan angka
 * sample:
 * onkeypress="return filterInput(1, event)"
 * onkeypress="return filterInput(1, event, false, '.')"
 */
function filterInput(filterType, evt, allowDecimal, allowCustom){ 
    var keyCode, Char, inputField, filter = ''; 
    var alpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; 
    var num   = '0123456789'; 
    
    // Get the Key Code of the Key pressed if possible else - allow 
    if(window.event){ 
        keyCode = window.event.keyCode; 
		evt = window.event; 
    } else if (evt)keyCode = evt.which; 
    else return true; 
    
    // Setup the allowed Character Set 
    if(filterType == 0) filter = alpha; 
    else if(filterType == 1) filter = num; 
    else if(filterType == 2) filter = alpha + num; 
    if(allowCustom)filter += allowCustom; 
    if(filter == '')return true; 
    
    // Get the Element that triggered the Event 
    inputField = evt.srcElement ? evt.srcElement : evt.target || evt.currentTarget; 
    
    // If the Key Pressed is a CTRL key like Esc, Enter etc - allow 
    if((keyCode==null) || (keyCode==0) || (keyCode==8) || (keyCode==9) || (keyCode==13) || (keyCode==27) )return true; 
    
    // Get the Pressed Character 
    Char = String.fromCharCode(keyCode); 
    
    // If the Character is a number - allow 
    if((filter.indexOf(Char) > -1)) return true; 
    
    // Else if Decimal Point is allowed and the Character is '.' - allow 
    else if(filterType == 1 && allowDecimal && (Char == '.') && inputField.value.indexOf('.') == -1)return true; 
    else return false; 
}

/**
 * Mengubah Comma Separated Value menjadi Array
 * Input  : 1,2,3
 * Output : [1,2,3]
 */
function fnCSV2Array(vString, vSep) {
	//var vString = document.test.txtTest.value;
	//var vSep = document.test.txtTest1.value;
	//alert('vString: ' + vString + '\nvSep: ' + vSep);
		
	var vStrLength = vString.length
	var vArrLength = 1;
	for (var a=0; a<=vStrLength; a++) {
		if (vString.charAt(a) == vSep) {
			vArrLength = vArrLength + 1; 
		}
	}
	//alert('vArrLength: ' + vArrLength);
	
	var vWord = new Array;
	var vIdxWord = 0;
	var vString2 = vString;
	var vOldIdx = 0;
	for (var a=0; a<=vString.length; a++) {
		if (vString.indexOf(vSep) > 0) {
			if (vString.charAt(a) == vSep) {
				vIdxSep = a;
				
				var vNullCheck = '';
				if (vOldIdx < vIdxSep) {
					vNullCheck = vString.substring(vOldIdx,vIdxSep);
				}
				if (vNullCheck == 'null') {
					vNullCheck = '';
				}
				//vWord[vIdxWord] = vString.substring(vOldIdx,vIdxSep);
				vWord[vIdxWord] = vNullCheck;
			
				vString2 = vString2.substring(vIdxSep+1,vString2.length);
				vIdxWord = vIdxWord + 1;
				vOldIdx = vIdxSep + 1; 
				
				if (vString.lastIndexOf(vSep) == a) {
					var vNullCheck1 = '';
					if ((a+1) < (vString.length)) {
						vNullCheck1 = vString.substring(a+1,vString.length);
					}
					if (vNullCheck1 == 'null') {
						vNullCheck1 = '';
					}
					//vWord[vArrLength-1] = vString.substring(a+1,vString.length);
					vWord[vArrLength-1] = vNullCheck1;
				}
			}
		} else {
			var vNullCheck = vString;
			if (vNullCheck == 'null') {
				vNullCheck = '';
			}
			//vWord[vIdxWord] = vString;
			vWord[vIdxWord] = vNullCheck;
		}
	}
	
	//for (var b=0; b<=vArrLength-1; b++) {
	//	alert('vWord['+b+']: ' + vWord[b]);
	//}
	return vWord;
}

/**
 * Menghitung Selisih Tanggal
 * Input  : DD/MM/YYYY
 * vDate1 : Tgl Awal
 * vDate2 : Tgl Akhir
 * Output : x Hari
 */
 	function dateDiff1(vDate1,vDate2) {
		//var vDate1 = document.getElementById("date1").value;
		//var vDate2 = document.getElementById("date2").value;
		
		var vDateAwal = new Date(getYear(vDate1),getMonth(vDate1),getDate(vDate1));
		var vDateAkhir = new Date(getYear(vDate2),getMonth(vDate2),getDate(vDate2));
		
		var vDateDiff = Math.floor(vDateAkhir/(1000*60*60*24)) - Math.floor(vDateAwal/(1000*60*60*24));
		//alert('vDateDiff: ' + vDateDiff);
		
		return vDateDiff;
	}
	
	function getYear(vDate) {
		// input  : 13/01/2009
		// output : 2009
		var vYear = vDate.substring(6,vDate.length);
		return vYear;
	}
	
	function getMonth(vDate) {
		// input  : 13/01/2009
		// output : 0, because month in JS is in 0 - 11
		var vMonth = vDate.substring(3,5);
		var vMonth1 = '';
		if (vMonth.substring(0,1) == 0) {
			vMonth1 = parseInt(vMonth.substring(1,2))-1;
		}
		return vMonth1;
	}
	
	function getDate(vDate) {
		// input  : 13/01/2009
		// output : 13
		var vDate1 = vDate.substring(0,2);
		return vDate1;
	}

/**
 * Hapus Format Angka
 * Input  : 1.000.000,00
 * Output : 1000000
 */
	function delNumFormat(vString) {
		//var vString = document.getElementById("test").value;
		var vString1 = delDecimal(vString);
		var vNewString = vString1.replace(/\W/g,"");
		//alert('vNewString: ' + vNewString);
		return vNewString;
	}
	
	function delDecimal(vString) {
		var vIdxDec = vString.lastIndexOf(",");
		var vNewString = vString.substring(0,vIdxDec);
		return vNewString;
	} 

/**
 * Mengubah format no registrasi peserta
 * Input  : 000003a
 * Output : 3a
 */	
	function cutIt2(x) {
		var vValue = x;
		if (vValue.charAt(0) == '0') {
   	        for (a=0; a<=(vValue.length-1); a++) {
       	        if (vValue.charAt(a)!= 0) {
           	        vNewValue = vValue.substring(a, vValue.length);
           	        return vNewValue;
               	    //break;
                }
   	        }
   	    } else {
   	    	vNewValue = vValue;
   	    	return vNewValue;
   	    }
    }

/**
 * Menghitung character no peserta 
 * Bila telah 14 digit, akan memindahkan kursor ke element berikutnya
 * Nama form harus disertakan
 */			
	function checkLen5(vElement, vElementValue, vNextElement, vForm){
		if (vElementValue.length == vElement.maxLength) {
        		document.getElementById(vForm).elements[vNextElement].focus();
        }
   	}
   	
/**
 * Menghitung character no peserta 
 * Bila telah 14 digit, akan menambahkan '/' secara otomatis
 * Output : 40056200800027/3a
 */			
	function checkLen3(vElement, vElementValue){
		var vIdxSelected;
		vIdxSelected = document.main_form.tipeSearch.selectedIndex;
		if (vIdxSelected == 1) {
			if (vElementValue.length == 14) {
        		var vOldValue = document.getElementById(vElement).value
   	    		var vNewValue = vOldValue + '/';
       			document.getElementById(vElement).value = vNewValue;
       		}
       	}
   	}
   	
/**
 * Menghitung character no peserta 
 * dropdownlist dan textbox
 * Bila telah 14 digit, akan menambahkan '/' secara otomatis
 * Output : 40056200800027/3a
 */			
	function checkLen4(vCekElement, vElement, vElementValue){
		var vIdxSelected = document.getElementById(vCekElement).selectedIndex;
		if (vIdxSelected == 1) {
			if (vElementValue.length == 14) {
        		var vOldValue = document.getElementById(vElement).value
   	    		var vNewValue = vOldValue + '/';
       			document.getElementById(vElement).value = vNewValue;
       		}
       	}
   	}  

/**
 * Cek List 
 * Automatic Search sesuai dgn yg diketikkan
 * komponen: textbox dan dropdownlist
 */   	
   	function cekList2(srcTxtBox, srcOption) {
		var vTextBox = document.getElementById(srcTxtBox).value;
		var vList = document.getElementById(srcOption);
		for (var a=0; a<=vList.length-1; a++) {
			if (vTextBox.toUpperCase() == vList[a].text.substring(0, vTextBox.length).toUpperCase()) {
				vList.selectedIndex = a;
				break;
			}
		}
	} 	
	
/**
 * Ubah ClassName utk Keperluan WaterMark
 */  	
	function waterMarkOn(elementId, defaultText) {
       	var textValue = document.getElementById(elementId).value;
  			if (textValue == defaultText || textValue.length == 0) {
     			document.getElementById(elementId).className = "watermark";
     			document.getElementById(elementId).value = defaultText;
  			} else {
     			document.getElementById(elementId).className = "normal";
     		}
       }
        
    function waterMarkOff(elementId, defaultText) {
       	if (document.getElementById(elementId).value == defaultText) {
   			document.getElementById(elementId).className = "normal";
   			document.getElementById(elementId).value = "";
 		}
    }
    
    /**
    function markedElement() {
		var vIdxSelected;
		vIdxSelected = document.main_form.tipeSearch.selectedIndex;
		var vValue = document.main_form.searchBox.value;
		var vClassName = document.main_form.searchBox.className;
		if (vIdxSelected == 0) {
			// no polis
			if (vValue == "" | vValue.length == 0) {
				document.main_form.searchBox.className = 'watermark';
				document.main_form.searchBox.value = "No Polis";
			} else {
				if (vClassName == 'watermark' && vValue != 'No Polis') {
					document.main_form.searchBox.className = 'watermark';
					document.main_form.searchBox.value = "No Polis";
				}
			}
		} else if (vIdxSelected == 1) {
			// no peserta
			if (vValue == "" | vValue.length == 0) {
				document.main_form.searchBox.className = 'watermark';
				document.main_form.searchBox.value = "No Polis / No Reg";
			} else {
				if (vClassName == 'watermark' && vValue != 'No Polis / No Reg') {
					document.main_form.searchBox.className = 'watermark';
					document.main_form.searchBox.value = "No Polis / No Reg";
				}
			}
		} else if (vIdxSelected == 2) {
			// nama peserta
			if (vValue == "" | vValue.length == 0) {
				document.main_form.searchBox.className = 'watermark';
				document.main_form.searchBox.value = "Nama";
			} else {
				if (vClassName == 'watermark' && vValue != 'Nama') {
					document.main_form.searchBox.className = 'watermark';
					document.main_form.searchBox.value = "Nama";
				}
			}
		} else if (vIdxSelected == 3) {
			// hospital
			if (vValue == "" | vValue.length == 0) {
				document.main_form.searchBox.className = 'watermark';
				document.main_form.searchBox.value = "Rumah Sakit";
			} else {
				if (vClassName == 'watermark' && vValue != 'Rumah Sakit') {
					document.main_form.searchBox.className = 'watermark';
					document.main_form.searchBox.value = "Rumah Sakit";
				}
			}
		} else if (vIdxSelected == 4) {
			// no batch
			if (vValue == "" | vValue.length == 0) {
				document.main_form.searchBox.className = 'watermark';
				document.main_form.searchBox.value = "No Batch";
			} else {
				if (vClassName == 'watermark' && vValue != 'No Batch') {
					document.main_form.searchBox.className = 'watermark';
					document.main_form.searchBox.value = "No Batch";
				}
			}
		} else if (vIdxSelected == 5) {
			// Nama Tertanggung
			if (vValue == "" | vValue.length == 0) {
				document.main_form.searchBox.className = 'watermark';
				document.main_form.searchBox.value = "Nama Tertanggung";
			} else {
				if (vClassName == 'watermark' && vValue != 'Nama Tertanggung') {
					document.main_form.searchBox.className = 'watermark';
					document.main_form.searchBox.value = "Nama Tertanggung";
				}
			}
		} else {
			// No Induk Kepegawaian
			if (vValue == "" | vValue.length == 0) {
				document.main_form.searchBox.className = 'watermark';
				document.main_form.searchBox.value = "No Induk Kepegawaian";
			} else {
				if (vClassName == 'watermark' && vValue != 'No Induk Kepegawaian') {
					document.main_form.searchBox.className = 'watermark';
					document.main_form.searchBox.value = "No Induk Kepegawaian";
				}
			}
		} 
	}
	*/
	
	function markedElement() {
		var vIdxSelected = document.main_form.tipeSearch.selectedIndex;
		var vTxtSelected = document.main_form.tipeSearch[vIdxSelected].text;
		var vValue = document.main_form.searchBox.value;
		var vClassName = document.main_form.searchBox.className;
		if (vValue == "" | vValue.length == 0) {
			document.main_form.searchBox.className = 'watermark';
			document.main_form.searchBox.value = vTxtSelected;
		} else {
			if (vClassName == 'watermark' && vValue != vTxtSelected) {
				document.main_form.searchBox.className = 'watermark';
				document.main_form.searchBox.value = vTxtSelected;
			}
		}
	}
	
	function unmarkedElement() {
		document.main_form.searchBox.className = 'normal';
		document.main_form.searchBox.value = "";
	}
	
	function markedElement(vTxtBox, vSlctList) {
		var vIdxSelected = document.getElementById(vSlctList).selectedIndex;
		var vTxtSelected = document.getElementById(vSlctList)[vIdxSelected].text;
		var vValue = document.getElementById(vTxtBox).value;
		var vClassName = document.getElementById(vTxtBox).className;
		if (vValue == "" | vValue.length == 0) {
			document.getElementById(vTxtBox).className = 'watermark';
			document.getElementById(vTxtBox).value = vTxtSelected;
		} else {
			if (vClassName == 'watermark' && vValue != vTxtSelected) {
				document.getElementById(vTxtBox).className = 'watermark';
				document.getElementById(vTxtBox).value = vTxtSelected;
			}
		}
	}
	
	function unmarkedElement(vTxtBox, vSlctList) {
		document.getElementById(vTxtBox).className = 'normal';
		document.getElementById(vTxtBox).value = "";
	}

/**
 * Check Key Code
 */
	function checkKeycode(e) {
			var keycode;
			var vCtrl = false;
	
			if (window.event) {
				keycode = window.event.keyCode;
			} else if (e) {
				keycode = e.which;
			}
	
			if (window.event.shiftKey) {
			    //alert('vShft');
			    vShft = true;
			}
	   
		  	if (window.event.ctrlKey) {
	    		//alert('vCtrl');
			    vCtrl = true;
			}
	   
			if (window.event.altKey) {
			    //alert('vAlt');
			    vAlt = true;
			}
	
			if (vCtrl && vShft && keycode == 49) {
				//alert('Ctrl + Shift + 1');
		    	btAction(1);
	    		return true;
			}
			
			if (vCtrl && vShft && keycode == 50) {
				//alert('Ctrl + Shift + 2');
		    	btAction(2);
	    		return true;
			}
			
			if (vCtrl && vShft && keycode == 51) {
				//alert('Ctrl + Shift + 3');
		    	btAction(3);
	    		return true;
			}	
			
			if (vCtrl && vShft && keycode == 52) {
				//alert('Ctrl + Shift + 4');
		    	btAction(4);
	    		return true;
			}
			if (vCtrl && vShft && keycode == 53) {
				//alert('Ctrl + Shift + 5');
		    	btAction(5);
	    		return true;
			}
			if (vCtrl && vShft && keycode == 54) {
				//alert('Ctrl + Shift + 6');
		    	btAction(6);
	    		return true;
			}
			if (vCtrl && vShft && keycode == 55) {
				//alert('Ctrl + Shift + 7');
		    	btAction(7);
	    		return true;
			}
			if (vCtrl && vShft && keycode == 56) {
				//alert('Ctrl + Shift + 8');
		    	btAction(8);
	    		return true;
			}
			if (vCtrl && vShft && keycode == 57) {
				//alert('Ctrl + Shift + 9');
		    	btAction(9);
	    		return true;
			}
			if (vCtrl && vShft && keycode == 48) {
				//alert('Ctrl + Shift + 0');
		    	btAction(0);
	    		return true;
			}
			if (vCtrl && vShft && keycode == 65) {
				//alert('Ctrl + Shift + A');
		    	btAction('A');
	    		return true;
			}
			if (vCtrl && vShft && keycode == 66) {
				//alert('Ctrl + Shift + B');
		    	btAction('B');
	    		return true;
			}
			if (vCtrl && vShft && keycode == 67) {
				//alert('Ctrl + Shift + C');
		    	btAction('C');
	    		return true;
			}
			if (vCtrl && vShft && keycode == 68) {
				//alert('Ctrl + Shift + D');
		    	btAction('D');
	    		return true;
			}
			if (vCtrl && vShft && keycode == 69) {
				//alert('Ctrl + Shift + E');
		    	btAction('E');
	    		return true;
			}
			if (vCtrl && vShft && keycode == 82) {
				//alert('Ctrl + Shift + R');
		    	btAction('R');
	    		return true;
			}
		}
		
/**
 * Zoom Image
 * origImage : image that hidden, used to get image original size
 * editImage : image that displayed
 * dropDownZoom : drop down to choose zoom factor
 */
 		function changePic(origImage, dropDownZoom, editImage) {
			var vWPic = document.getElementById(origImage).width;
			var vHPic = document.getElementById(origImage).height;
			//alert('Width: ' + vWPic + '\nHeight: ' + vHPic);
		
			var vIdxSelected = document.getElementById(dropDownZoom).selectedIndex;
			var vZoom = document.getElementById(dropDownZoom)[vIdxSelected].value;
		
			var vZWPic = parseInt(vWPic) * parseInt(vZoom) / 100;
			var vZHPic = parseInt(vHPic) * parseInt(vZoom) / 100;
			//alert('ZWidth: ' + vZWPic + '\nZHeight: ' + vZHPic);
		
			document.getElementById(editImage).style.width = vZWPic;
			document.getElementById(editImage).style.height = vZHPic;
		}
		
/**
 * Auto Change Image Size
 * origImage : image that hidden, used to get image original size
 * editImage : image that displayed
 * ukuranBaru : new percentage of image
 */
 		function autoChangePic(origImage, ukuranBaru, editImage) {
			var vWPic = document.getElementById(origImage).width;
			var vHPic = document.getElementById(origImage).height;
			//alert('Width: ' + vWPic + '\nHeight: ' + vHPic);
		
			//var vIdxSelected = document.getElementById(dropDownZoom).selectedIndex;
			//var vZoom = document.getElementById(dropDownZoom)[vIdxSelected].value;
		
			var vZWPic = parseInt(vWPic) * parseInt(ukuranBaru) / 100;
			var vZHPic = parseInt(vHPic) * parseInt(ukuranBaru) / 100;
			//alert('ZWidth: ' + vZWPic + '\nZHeight: ' + vZHPic);
		
			document.getElementById(editImage).style.width = vZWPic;
			document.getElementById(editImage).style.height = vZHPic;
		}		
		
/**
 * Rotate Image
 * editImage : image that displayed
 * dropDownRot : drop down to choose degree of rotation
 * only work for IE
 */
 		function rotatePic(dropDownRot, editImage) {
			var vIdxSelected = document.getElementById(dropDownRot).selectedIndex;
			var vRotate = document.getElementById(dropDownRot)[vIdxSelected].value;
			if (vRotate == '0') {
				//alert('Rotate 0');
				document.getElementById(editImage).style.filter='progid:DXImageTransform.Microsoft.BasicImage(rotation=0)';
			} else if (vRotate == '90') {
				//alert('Rotate 90');
				document.getElementById(editImage).style.filter='progid:DXImageTransform.Microsoft.BasicImage(rotation=1)';
			} else if (vRotate == '180') {
				//alert('Rotate 180');
				document.getElementById(editImage).style.filter='progid:DXImageTransform.Microsoft.BasicImage(rotation=2)';
			} else if (vRotate == '270') {
				//alert('Rotate 270');
				document.getElementById(editImage).style.filter='progid:DXImageTransform.Microsoft.BasicImage(rotation=3)';
			}
		}	
		
/**
 * Menghilangkan tanda titik dan koma pada rupiah
 */			
		function dropCurrencySign(number) {
			var vNumber = number.replace(/\.|\,00/g, "");
			return vNumber
		}

/**
 * Memberi nama setiap element
 * dan tabIndex
 */
 		function fnGetAllElement() {
			var vJmlElement = document.main_form.elements.length;
			for (var w=0; w<=vJmlElement-1; w++) {
				// setting tab index
				document.main_form.elements[w].tabIndex = w+1;
				// setting tooltip
				var vElementName = '';
				if (document.main_form.elements[w].name != null) {
					vElementName = document.main_form.elements[w].name;
				} else {
					vElementName = document.main_form.elements[w].id;
				}
				document.main_form.elements[w].title = (w+1) + ' - ' + vElementName;
				//document.main_form.elements[w].onfocus = fnLastElement(vElementName);
			}
		}
				
/**
 * Menyimpan data element terakhir yang digunakan
 */
 		function fnLastElement(vElement) {
			document.main_form.hidLastElement.value = vElement;	
		}
		
/**
 * Menuju element terakhir yang digunakan
 */		
		function fnGotoLastElement() {
			var vLastElement = document.main_form.hidLastElement.value;
			document.getElementById(vLastElement).focus();
		}		
		
/**
 * Menuliskan tanda ribuan pada saat mengetik
 */
 	  function formatAngka(b) {
	  	var vValue0 = b.value;
	  	vValue = dropCurrencySign(vValue0).replace(/[^\d]/g,"");
	  	var vValLength = vValue.length;
	  	var vCek = "";
	  	if (vValLength > 3) {
	  		var vCount = 0;
	  		for (var a=vValLength; a>0; a--) {
	  			vCount = vCount + 1;
	  			if ((vCount%3 == 1) && (a != vValue.length)) {
	  				vCek = vValue.substring(0,a) + "." + vValue.substring(a,vValue.length);
	  			} else if ((vCount%3 == 1) && (a == vValue.length)) {
	  				vCek = vValue.substring(0,a) + vValue.substring(a,vValue.length);
	  			}
	  			vValue = vCek;
	  		}
	  		//alert('vCount: ' + vCount + '\nvValue: ' + vValue);
	  	}
	  	return vValue;
	  }
	  
/**
 * Menghapus isi kolom pada saat mulai mengetik
 */
 	  function delContent(compName, compValue) {
 	  	if ((compValue == "0,00") || (compValue == "0")) {
	  		document.getElementById(compName).value = '';
	  	}
	  }	  
	  
/**
 * Setting tabIndex
 */
 	function fnCheckTabStop() {
      var vJmlElement = document.main_form.elements.length;
			for (var w=0; w<=vJmlElement-1; w++) {
				document.main_form.elements[w].tabIndex = w+1;
			}
    }  